{# SPDX-FileCopyrightText: © 2015, 2020 Siemens AG
   SPDX-FileCopyrightText: © 2020 Robert Bosch GmbH
   SPDX-FileCopyrightText: © Dineshkumar Devarajan <Devarajan.Dineshkumar@in.bosch.com>

   SPDX-License-Identifier: FSFAP
#}
{% extends "include/base.html.twig" %}

{% block content %}
  
      
  {{ 'Select the folder that contains the upload'|trans }}: 
  {% include 'components/select-folder.html.twig' with {'name':'folderselect','id':'folderselect','selected':folderId} %}
  <br/><br/>
  {{ 'Apply same permissions to all uploads in this folder: '|trans }}<input type="checkbox" style="position:absolute;margin-left:5px;" {% if allUploadsPerm %} checked {% endif %} id="alluploadsperm" name="alluploadsperm" value="1">
  <br/><br/>
  {% if uploadList is empty %}
    {{ 'You have no permission to change permissions on any upload in this folder.'|trans }}
  {% else %}
    {{ 'Select the upload you wish to edit'|trans }}:
    <select id="uploadselect" {% if allUploadsPerm %} disabled {% endif %} name="uploadselect" class="ui-render-select2">
    {% for upload in uploadList %}
      <option value="{{ upload.upload_pk }}"{% if upload.upload_pk==uploadId %} selected="selected"{% endif %}>{{ upload.name|e }},
        {{ upload.upload_ts  }}</option>
    {% endfor %}
    </select>
    <br/><br/>
    {% import 'include/macros.html.twig' as macro %}
    {{ "Public Permission"|trans }}:
    {{ macro.select('publicpermselect',permNames,'publicpermselect',publicPerm) }}
    
    <p><table border="1">
      <tr><th>{{ 'Group'|trans }}</th><th>{{ 'Permission'|trans }}</th></tr>
      {% for permGroup in permGroups %}
      <tr>
        <td>{{ permGroup.group_name|e }}</td>
        <td>
          {{ macro.select('permselect',permNames,'permselect'~permGroup.perm_upload_pk,permGroup.perm,'data-puid="'~permGroup.perm_upload_pk~'"') }}
        </td>
      </tr>
      {% endfor %}
      {% if additableGroups is not empty %}
      <tr>
        <td>
          {{ macro.select('groupselectnew', additableGroups, 'groupselectnew', newGroup, 'class="ui-render-select2"') }}
        </td>
        <td>
          {% if permNamesWithReuse is defined %}
            {{ macro.select('permselectnew',permNamesWithReuse,'permselectnew',newPerm) }}
          {% else %}
            {{ macro.select('permselectnew',permNames,'permselectnew',newPerm) }}
          {% endif %}
        </td>
      </tr>
      {% endif %}
    </table>    
    
    {{ "All upload permissions take place immediately when a value is changed. There is no submit button."|trans }}<br/>
    {% if additableGroups is not empty %}
      {{ "Add new groups on the last line."|trans }}
      {{ 'If the clearing for the upload is in progress or ready for your recent group, the reuser can copy these.'|trans }}
    {% endif %}
  {% endif %}
  <h2>{{ "Look up who is a member of group "|trans }}</h2>
  {{ "To edit group memberships "|trans }} <a href="?mod=group_manage_users">{{ "click here"|trans }}</a>
  <br/>
  {{ 'To list the users in a group, select the group'|trans }}: <select id="groupsForGum" class="ui-render-select2">
  {% for gId,gName in groupArray %}
    <option value="{{ gId }}">{{ gName|e }}</option>
  {% endfor %}
  </select>
  <table id="tblUsers">
  </table>
    
{% endblock %}

{% block foot %}
  {{ parent() }}
  <script src="scripts/jquery.dataTables.min.js" type="text/javascript"></script>
  <script src="scripts/jquery.dataTables.select.js" type="text/javascript"></script>
  <script type="text/javascript">
    dataTableConfig = {
      "aaData":{{ gumJson }},
      "sPaginationType": "listbox",
      "aoColumns": [
        {"sTitle": "{{ 'User'|trans }}", "sClass": "left", "sWidth": "200px"},
        {"sTitle": "Group", "bVisible": false}
      ],
      "iDisplayLength": 50
    };

    var oTable = $('#tblUsers').dataTable(dataTableConfig);
    $('#groupsForGum').change( function() { oTable.fnFilter( $(this).val(), 1 ); } );
    $('#groupsForGum').trigger('change');
    
    $('#folderselect').change(function(){
      window.location.assign('{{ baseUri }}&folder='+$(this).val());
    });
    
    $('#uploadselect').change(function(){
      window.location.assign('{{ baseUri }}&folder={{ folderId }}&upload='+$(this).val());
    });

    $('#alluploadsperm').change(function(){
      var allUploads = document.getElementById("alluploadsperm");
      if (allUploads.checked == true) {
        window.location.assign('{{ baseUri }}&folder={{ folderId }}&alluploadsperm='+$(this).val());
      } 
     if (allUploads.checked == false) {
        window.location.assign('{{ baseUri }}&folder={{ folderId }}&alluploadsperm=0');
      }
    });
    
    $('#publicpermselect').change(function(){
      window.location.assign('{{ baseUri }}&folder={{ folderId }}&upload={{ uploadId }}&alluploadsperm={{ allUploadsPerm }}&public='+$(this).val());
    });
    
    $('#groupselectnew').change(function(){
      window.location.assign('{{ baseUri }}&folder={{ folderId }}&upload={{ uploadId }}&alluploadsperm={{ allUploadsPerm }}&newperm={{ newPerm }}&newgroup='+$(this).val());
    });

    $('#permselectnew').change(function(){
      window.location.assign('{{ baseUri }}&folder={{ folderId }}&upload={{ uploadId }}&alluploadsperm={{ allUploadsPerm }}&newgroup={{ newGroup }}&newperm='+$(this).val());
    });
    
    $('select[name=permselect]').change(function(){
      window.location.assign('{{ baseUri }}&folder={{ folderId }}&upload={{ uploadId }}&permupk='+$(this).attr('data-puid')+'&perm='+$(this).val());
    });
    
  </script>
{% endblock %}
